package parser;
import java.io.*;
import java.util.*;
import antlr.Token;

public abstract class LocalScope extends Scope {
    
    LocalScope(Scope enclosing) {
        if (enclosing instanceof LocalScope) {
            this.enclosing = (LocalScope)enclosing;
            this.depth = this.enclosing.depth + 1;
        } else {
            this.depth = 0;   
        }
        used = new BitSet();
        locals = new BitSet();
        globals = new BitSet();
    }
    
    BitSet used;
    BitSet locals;
    BitSet globals;
    int depth;

    void global(int name) {
        globals.set(name);
        locals.clear(name);
    }
    
    protected LocalScope enclosing;
        
    void bind(int name) {
        locals.set(name, !globals.get(name));
    }

    Stmt discard(Expr e) {
        return e.toStm();   
    }

    abstract Type variable(int name);

    abstract Type escape(int name, int depth);
     
    Expr name(int name) {
        used.set(name);
        return new LocalVariable(name, this);
    }
    
    void close() {
    }
    
    boolean escapes;

}
